#ifndef _NET_IF_H
#define _NET_IF_H

#define IF_NAMESIZE 16

struct if_nameindex {
  unsigned int if_index;
  const char *if_name;
};

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/**
 * # Safety
 * Returns a constant pointer to a pre defined const stub list
 * The end of the list is determined by an if_nameindex struct having if_index 0 and if_name NULL
 */
const struct if_nameindex *if_nameindex(void);

/**
 * # Safety
 * this is a no-op: the list returned by if_nameindex() is a ref to a constant
 */
void if_freenameindex(struct if_nameindex *s);

/**
 * # Safety
 * Compares the name to a constant string and only returns an int as a result.
 * An invalid name string will return an index of 0
 */
unsigned int if_nametoindex(const char *name);

/**
 * # Safety
 * Returns only static lifetime references to const names, does not reuse the buf pointer.
 * Returns NULL in case of not found + ERRNO being set to ENXIO.
 * Currently only checks against inteface index 1.
 */
const char *if_indextoname(unsigned int idx, char *buf);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif /* _NET_IF_H */
